package wwl.lsf.hellospringboot.baidu;


import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import java.net.URLEncoder;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;

/**
 * 通用文字识别
 */
public class GeneralBasic {

  /**
   * 重要提示代码中所需工具类
   * FileUtil,Base64Util,HttpUtil,GsonUtils请从
   * https://ai.baidu.com/file/658A35ABAB2D404FBF903F64D47C1F72
   * https://ai.baidu.com/file/C8D81F3301E24D2892968F09AE1AD6E2
   * https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3
   * https://ai.baidu.com/file/470B3ACCA3FE43788B5A963BF0B625F3
   * 下载
   */
  public static String generalBasic(String base64) {
    // 请求url
//    String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic";
    String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate_basic";//高精度版本
    try {
      String imgParam = URLEncoder.encode(base64, "UTF-8");

      String param = "image=" + imgParam;

      // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
      String accessToken = AuthService.getAuth();

      String result = HttpUtil.post(url, accessToken, param);

      return result;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }

  public static void main(String[] args) {
    GeneralBasic.generalBasic("/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAAZAFADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo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